﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_dinhmuc_thanhphamInfo
    {
        private int _id_dinhmuc;
        private int _mamonan;
        private int _mahh;
        private double _soluonghh;
        private string _ghichu;

        public cs_erp_dinhmuc_thanhphamInfo(int id_dinhmuc, int mamonan, int mahh, double soluonghh, string ghichu)
        {
            this._id_dinhmuc = id_dinhmuc;
            this._mamonan = mamonan;
            this._mahh = mahh;
            this._soluonghh = soluonghh;
            this._ghichu = ghichu;

        }
        public cs_erp_dinhmuc_thanhphamInfo()
        {
            this._id_dinhmuc = 0;
            this._mamonan = 0;
            this._mahh = 0;
            this._soluonghh = 0;
            this._ghichu = " ";

        }
        public int id_dinhmuc
        {
            get
            {
                return this._id_dinhmuc;
            }
            set
            {
                this._id_dinhmuc = value;
            }
        }
        public int mamonan
        {
            get
            {
                return this._mamonan;
            }
            set
            {
                this._mamonan = value;
            }
        }
        public int mahh
        {
            get
            {
                return this._mahh;
            }
            set
            {
                this._mahh = value;
            }
        }
        public double soluonghh
        {
            get
            {
                return this._soluonghh;
            }
            set
            {
                this._soluonghh = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[6];
            paraName[0] = "@id_dinhmuc";
            paraName[1] = "@mamonan";
            paraName[2] = "@mahh";
            paraName[3] = "@soluonghh";
            paraName[4] = "@ghichu";
            paraName[5] = "@option";
            object[] paraValue = new object[6];
            paraValue[0] = this._id_dinhmuc;
            paraValue[1] = this._mamonan;
            paraValue[2] = this._mahh;
            paraValue[3] = this._soluonghh;
            paraValue[4] = this._ghichu;
            paraValue[5] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 6, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_DINHMUC_THANHPHAM", option);
        }

        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_DINHMUC_THANHPHAM", "");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_dinhmuc = Convert.ToInt32(ds.Tables[0].Rows[0]["id_dinhmuc"].ToString().Trim());
                this._mamonan = Convert.ToInt32(ds.Tables[0].Rows[0]["mamonan"].ToString().Trim());
                this._mahh = Convert.ToInt32(ds.Tables[0].Rows[0]["mahh"].ToString().Trim());
                this._soluonghh = Convert.ToDouble(ds.Tables[0].Rows[0]["soluonghh"].ToString().Trim());
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                return 1;
            }
            catch
            {
                return -1;
            }
        }
    }
}
